package com.qf.admin.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qf.admin.domain.SendMessage;
import com.qf.admin.domain.User;
import com.qf.admin.mapper.MessageMapper;
import com.qf.admin.service.IMessageService;
import com.qf.commons.TableData;
import com.qf.pojo.QueryUser;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author He
 * @Date: 2020/10/22 11:25
 * @Description :
 */
@Service
public class MessageServiceImpl implements IMessageService {
    private MessageMapper messageMapper;

    public MessageServiceImpl(MessageMapper messageMapper) {
        this.messageMapper = messageMapper;
    }

    @Override
    public TableData<SendMessage> getPageData(QueryUser queryUser, int offset, int limit) {
        Page<SendMessage> page = PageHelper.offsetPage(offset, limit);
        messageMapper.getPageData(queryUser);

        TableData<SendMessage> tableData = new TableData<>();
        //封装结构List<User>
        tableData.setRows(page.getResult());
        //封装条数
        tableData.setTotal((int) page.getTotal());
        return tableData;
    }

    @Override
    public List<User> getUser() {
        return messageMapper.getUser();
    }
}
